<template>
  <div>
    <upload :multiple="false" accept=".mp4" text="上传视频" @onSuccess="onSuccess"></upload>
    <video :src="url" :poster="url + '?vframe/jpg/offset/1'" v-if="url" class="video" controls="controls" style="height:200px"></video>
  </div>
</template>

<script>
import Upload from "@/components/Upload";
import { conmitCocourseQuestions } from "@/api/course";
export default {
  components: {
    Upload,
  },
  props: {
    reviewList: {
      type: Array,
      default() {
        return []
      }
    },
  },
  computed:{
    url(){
      return this.list[0].question_stem
    }
  },
  watch: {
    reviewList: {
      handler(data) {
        console.log(data)
        if (data && data.length === 0) {
          return false
        }
        let list = JSON.parse(JSON.stringify(data));
        this.list[0].question_stem = list[0].question_stem;
      },
      immediate: true,
      deep: true,
    }
  },
  data() {
    return {
      list: [{
        question_stem: '',
      }]
    }
  },
  created() {

  },
  methods: {
    async conmitCocourseQuestions() {
      let res = await conmitCocourseQuestions({
        question_category: 2,
        course_question_set_id: this.$route.query.id,
        list: JSON.stringify(this.list)
      })
      this.$message({
        message: '操作成功！',
        type: 'success'
      });
      this.$emit('close')
    },
    onSuccess(url) {
      this.url = url[0];
      //this.list[0].question_stem.splice(0,this.list[0].question_stem.length);
      //this.list[0].question_stem = [];
      this.list[0].question_stem= url[0]; 
      this.conmitCocourseQuestions();
    }
  },
}
</script>
<style lang="scss" scoped>
.video {
  height: 150px;
  margin-top: 20px;
}
</style>
